import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import AutoImport from 'unplugin-auto-import/vite'
import { resolve } from 'path';
import UnoCSS from 'unocss/vite'

const pathResolve = (pathStr: string) => {
  return resolve(__dirname, pathStr)
}

export default defineConfig({
  base: '/',
  publicDir: "public",
  plugins: [
    react(),
    AutoImport({
      imports: ['react','react-router-dom','react-i18next','ahooks'],
      dts: true,
    }),
    UnoCSS({configFile: './uno.config.ts'})
  ],
  resolve: {
    alias: {
      '@': pathResolve('src'),
    }
  },
  server: {
    proxy: {
      '/socket.io': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        ws: true, // 支持 websocket
        rewrite: (path) => path.replace(/^\/socket.io/, '')
      }
    }
  }
})
